package com.cdc.network.presenter;


import com.cdc.http.http1.HttpListener;
import com.cdc.http.http1.Request;
import com.cdc.http.http1.RequestExecutor;
import com.cdc.http.http1.RequestMethod;
import com.cdc.http.http1.Response;
import com.cdc.network.view.DrawBaseView;

import java.util.Map;

/**
 * Created by admin on 2018/4/14.
 */

public class DrawBasePresenterImpl2 implements DrawBasePresenter{
    private DrawBaseView drawBaseView;

    @Override
    public void attachView(DrawBaseView v) {
        this.drawBaseView=v;
    }

    @Override
    public void detachView() {
        drawBaseView=null;
    }

    @Override
    public void get(String url) {
        Request request=new Request(url, RequestMethod.GET);
        RequestExecutor.INSTANCE.execute(request, new HttpListener() {
            @Override
            public void onSuccesed(Response response) {
                byte[]  b=response.getResult();
                String str=new String(b);
                drawBaseView.setResult(str);
            }

            @Override
            public void onFail(Exception e) {

            }
        });
    }

    @Override
    public void post(String url) {
        Request request=new Request(url, RequestMethod.POST);
        RequestExecutor.INSTANCE.execute(request, new HttpListener() {
            @Override
            public void onSuccesed(Response response) {
                byte[]  b=response.getResult();
                String str=new String(b);
                drawBaseView.setResult(str);
            }

            @Override
            public void onFail(Exception e) {

            }
        });
    }

    @Override
    public void post(String url, String json) {
        Request request=new Request(url, RequestMethod.POST);
        
        RequestExecutor.INSTANCE.execute(request, new HttpListener() {
            @Override
            public void onSuccesed(Response response) {
                byte[]  b=response.getResult();
                String str=new String(b);
                drawBaseView.setResult(str);
            }

            @Override
            public void onFail(Exception e) {

            }
        });
    }

    @Override
    public void upload(String url, Map<String, Object> maps) {

    }

    @Override
    public void uploads(String url, Map<String, Object> maps) {

    }
}
